package com.explam.springboot.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class URLConfig implements WebMvcConfigurer {

    @org.springframework.beans.factory.annotation.Value("${pictureFile.path}")
    private String picturePath;

    @Value("${pictureFile.path-mapping}")
    private String picturePath_mapping;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        将请求路径映射到本地文件:
//        请求路径：http://localhost:8888/test/picture/2.jpeg  (picturePath_mapping)->虚拟目录
//        本地资源地址：E:\pictures\2.jpeg                      (picturePath)->电脑本地环境
        registry.addResourceHandler(picturePath_mapping+"**").addResourceLocations("file:"+picturePath);

    }
}

